package com.hn658.groupshare.backend.action.user.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.hn658.framework.common.AbstractBaseService;
import com.hn658.framework.common.IServiceResponse;
import com.hn658.framework.shared.context.UserContext;
import com.hn658.groupshare.backend.action.user.ILoginAction;
import com.hn658.groupshare.backend.util.AuthCookieEditor;
import com.hn658.groupshare.common.vo.CommonResponse;
import com.hn658.groupshare.core.service.ISessionService;
/**
 * 
 * @author ztjie
 *
 */
@Controller("loginAction")
@Path("login")
@Produces("application/json; charset=UTF-8")
@Consumes("application/json; charset=UTF-8")
public class LoginAction extends AbstractBaseService implements ILoginAction {
	
	@Autowired
	private ISessionService sessionService;

	@Path("logout")
	@Consumes("text/html; charset=UTF-8")
	@GET
	public IServiceResponse logout(@Context HttpServletRequest request, @Context HttpServletResponse response) {
		sessionService.removeSession(UserContext.getCurrentUserId());
		//失效Cookie
		AuthCookieEditor.invalidateCookie(request, response);
		CommonResponse res = new CommonResponse();
		this.success(res);
		return res;
	}

}
